# _*_ coding : utf-8 _*_
# @Time : 2022/8/10 10:42
# @Author : Moonquake
# @File : 19.xpath
# @Project : python
from lxml import etree

#x path解析
# 1.本地文件
# etree.parse
tree = etree.parse('xpath.html')
print(tree)
# tree.xpath('xpath路径')

# 查找ul下面的li
li_list = tree.xpath('//body/ul/li')

# 查找有ID属性的li标签
# text() 获取标签中的内容
id_list = tree.xpath('//ul/li[@id]/text()')

# 找到id为1的li标签
id1_list = tree.xpath('//ul/li[@id="l1"]/text()')

# 找到id中包含l的li标签(模糊查找)
li1_list = tree.xpath('//ul/li[contains(@id,"l")]/text()')
print(li1_list)

# 查询id以 l 开头的li标签
li2_list = tree.xpath('//ul/li[starts-with(@id,"l")]/text()')

# 2.服务器响应的数据 response.read().decode('utf-8')
# etree.HTML



